package com.gary.promethues.pushgateway;

import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Gauge;
import io.prometheus.client.exporter.PushGateway;

import java.util.HashMap;
import java.util.Map;

/**
 * @author peng_rui
 * @date 2022/2/24
 */
public class PushGatewayTest {
    public static void main(String[] args) {
        try{
            String url = "120.55.99.182:9091";
            CollectorRegistry registry = new CollectorRegistry();
            Gauge guage = Gauge.build("gary_custom_metric", "This is gary custom metric.").create();
            guage.set(23.12);
            guage.register(registry);
            PushGateway pg = new PushGateway(url);
            Map<String, String> groupingKey = new HashMap<>(16);
            groupingKey.put("appName", "web-center");
            groupingKey.put("ip", "120.55.99.182");
            groupingKey.put("port", "1123");
            groupingKey.put("status", "UP");
            groupingKey.put("details", "{\"status\":\"UP\",\"details\":{\"nacosDiscovery\":{\"status\":\"UP\"},\"diskSpace\":{\"status\":\"UP\",\"details\":{\"total\":\"148679684096\",\"free\":\"97515159552\",\"threshold\":\"10485760\"}},\"refreshScope\":{\"status\":\"UP\"},\"discoveryComposite\":{\"status\":\"UP\",\"details\":{\"discoveryClient\":{\"status\":\"UP\",\"details\":{\"services\":[\"archRouteCommonGateway\",\"hc-archhas-center\",\"fuse-center\",\"hc-web-archhasadmin\",\"hc-web-archhas\",\"archcommonservice-center\"]}}}}}}");
            pg.pushAdd(registry, "app_health_check", groupingKey);
        } catch (Exception e){
            e.printStackTrace();
        }
    }
}
